package LeetCode;

import sun.applet.Main;

class Solution {
    public  static int  searchInsert(int[] nums, int target) {
        if(nums == null || nums.length ==0) return 0;
        if(target<nums[0]) return 0;
        else if(target>nums[nums.length-1]) return nums.length;
        else{
            for(int i =0 ; i<nums.length -1 ; i++){
                if(nums[i] == target) return i;
                if(target > nums[i] && target <nums[i+1])
                    return i+1;

            }
        }
        return 0;
    }

    public static void main(String[] args) {
        int [] a = {1,2,3,4,5};
        int i = searchInsert(a, 3);
        System.out.println(i);
    }
}